package com.yc.behavioral.strategy.impl;

import com.yc.behavioral.strategy.CalcStrategy;

import java.math.BigDecimal;

public class DivStrategy implements CalcStrategy {
	@Override
	public Double execuCalc(Double num1, Double num2) {
		if (num2 == 0d || num2 == null) {
			System.out.println("被除数不能为0 或者 空");
			return 0d;
		}
		if (num1 == 0d || num1 == null) {
			return 0d;
		}
		BigDecimal b1 = new BigDecimal(Double.toString(num1));
		BigDecimal b2 = new BigDecimal(Double.toString(num1));
		return new Double(b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue());
	}
}
